package andris.android.mobilarena.provider;

import java.util.List;

import andris.android.mobilarena.R;
import andris.android.mobilarena.model.Article;
import android.app.Activity;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainListAdapter extends BaseAdapter {

	private final List<Article> mArticles;
	private final LayoutInflater mLayoutInflater;

	public MainListAdapter(Activity activity, List<Article> articles) {
		super();
		mArticles = articles;
		mLayoutInflater = activity.getLayoutInflater();
	}

	@Override
	public int getCount() {
		return mArticles.size();
	}

	@Override
	public Object getItem(int position) {
		return mArticles.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout listItem = (LinearLayout) convertView;

		if (listItem == null)
			listItem = (LinearLayout) mLayoutInflater.inflate(R.layout.main_list_item, null);

		TextView title = (TextView) listItem.findViewById(R.id.main_list_text_title);
		title.setText(mArticles.get(position).getTitle());
		
		TextView lead = (TextView) listItem.findViewById(R.id.main_list_text_lead);
		lead.setText("A One széria csúcsa jött, látott és győzött: prémium anyaghasználat, ütős formaterv és előremutató hardver jellemzi a HTC újdonságát.");
		
		TextView time = (TextView) listItem.findViewById(R.id.main_list_text_time);
		time.setText(Html.fromHtml("22"));
		
		TextView community = (TextView) listItem.findViewById(R.id.main_list_text_community);
		community.setText(Html.fromHtml("356"));

		return listItem;
	}
}
